package testJ;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;

public class test1 {


    public static void main(String[] args) {
        //输出方法id为1 的name
        Password pw = new Password();

        Method[] em = pw.getClass().getMethods();
        for (Method method : em) {
            UserCode us = method.getAnnotation(UserCode.class);
            if(us != null)
                System.out.println(us.name());
        }
    }
}
class Password{
    @UserCode(id = 1,name = "中国")
    public void a1(){};
    @UserCode(id=2)
    public void a2(){};
}
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface UserCode{
    public int id();
    public String name() default "美国";
}